<template>
    <div v-loading.fullscreen.lock="isLoading" element-loading-text="加载中">
        <el-header style="height: 100px">
            <div class="tit">
                <el-logo @click="index()"></el-logo>
                <div class="right">
                    <img src="../../assets/images/login/phone.png" alt="" />
                    <span>{{ tel }}</span>
                </div>
            </div>
        </el-header>
        <div class="box">
            <img src="../../assets/images/login/bg.png" alt="" style="" />
            <div class="con">
                <div class="cc">长春人才集团</div>
                <div class="zx">在线招聘平台</div>
                <div class="job">招才引才、找工作、职业指导平台</div>
                <div class="info">
                    <div class="linebb"></div>
                    <el-tabs v-model="activeName" @tab-click="handleClick">
                      

                        <el-tab-pane label="单位用户" name="second">
                            <el-input v-model="mobilesecond" placeholder="请输入手机号" type="tel" maxlength="11" minlength="11"
                                @blur="validateMobileBlurSecond"></el-input>
                            <el-input placeholder="请输入密码" v-model="passwordsecond" show-password v-if="pswshowa"></el-input>
                            <div class="code" v-if="codeshowa">
                                <el-input placeholder="请输入验证码" v-model="mobile_code"></el-input>
                                <button class="send" @click="sendcodea" ref="sendBtn"
                                    :class="{ 'disabled': isSending, 'send': countdown > 0 }">
                                    {{ isSending && countdown > 0 ? `重新发送${countdown}` : '发送验证码' }}
                                </button>
                            </div>
                            <div class="codelogin" @click="codeloginaa" v-if="codetextshowa">
                                短信验证码登录
                            </div>
                            <div class="codelogin" @click="pswloginaa" v-else>
                                手机号密码登录
                            </div>
                            <div class="checkBtnInfo">
                                <input class="inputcheck1" type="checkbox" @click="checkPrivacy"
                                    :checked="checkFlag" />已阅读并同意<span @click="serviceAgreement">《用户服务协议》</span>和<span
                                    @click="privacyAgreement">《隐私协议》</span>
                            </div>
                            <button class="login" @click="loginsecond">登录</button>
                            <div class="come">
                                还没有账号? <span @click="register">立即注册</span>
                                <div class="forget_login" @click="forgetLogin(2)">
                                    忘记密码？
                                </div>
                            </div>
                        </el-tab-pane>
                    </el-tabs>
                </div>
            </div>
        </div>
        <div class="alert" v-if="alertshow">
            <div class="alertbox">
                <div class="title">用户服务协议</div>
                <div class="line1"></div>
                <div class="content" v-html="zp_agreement.content" ref="scrollView1" @scroll="handleScroll"></div>
                <div class="line2"></div>
                <el-button class="confirm" @click="confirm" :class="{ 'is-red': isBottom, 'is-disabled': !isBottom }"
                    :disabled="!isBottom">
                    确认
                </el-button>
            </div>
        </div>
        <div class="alert" v-if="alertshow1">
            <div class="alertbox">
                <div class="title">用户隐私政策</div>
                <div class="line1"></div>
                <div class="content" v-html="zp_agreement.content" ref="scrollView" @scroll="handleScroll1"></div>
                <div class="line2"></div>
                <el-button class="confirm" @click="confirm" :class="{ 'is-red': isBottoma, 'is-disabled': !isBottoma }"
                    :disabled="!isBottoma">确认</el-button>
            </div>
        </div>
        <el-footerss></el-footerss>
    </div>
</template>

<script>
import elLogo from "../../common/elLogo.vue";
import elFooterss from "../../common/elFooterss.vue";
import { mapState } from "vuex";
import { smsUrl } from '../../utils/baseUrl.js'

export default {
    data() {
        return {
            index_base: [],
            isSending: false, // 发送验证码  
            countdown: 60, // 倒计时秒数  
            timer: null, // 定时器 
            input: "",
            activeName: "second",
            mobile: "",
            password: "",
            mobilesecond: "",
            passwordsecond: "",
            mobile_code: "",
            codeshow: false,
            codetextshow: true,
            pswshow: true,
            codeshowa: false,
            codetextshowa: true,
            pswshowa: true,

            checkFlag: false, //check选中
            readFlag: false, //阅读协议
            alertshow: false,
            alertshow1: false,
            zp_agreement: [],
            redbtnshow: false,
            disbtnshow: true,
            redbtnshow1: false,
            disbtnshow1: true,
            scene: 'login',
            isBottoma: false,
            isBottom: false, // 用来追踪是否滚动到底部的标志
            isLoading: false,
        };
    },
    computed: {
        ...mapState(["IndexBase"]),
        tel() {
            return this.IndexBase ? this.IndexBase.tel : null;
        },
    },
    beforeDestroy() {
        window.removeEventListener("scroll", this.checkScroll);
    },
    methods: {
        checkTokenAndRedirect() {
            const token = localStorage.getItem("token");
            if (token) {
                localStorage.removeItem("token");
                this.$router.push("/index");
            }
        },
        // 职位发布规则滚动
        handleScroll() {
            const scrollView = this.$refs.scrollView1;
            if (
                scrollView.scrollHeight -
                scrollView.scrollTop -
                scrollView.clientHeight <=
                10
            ) {
                this.isBottom = true;
            } else {
                this.isBottom = false;
            }
        },
        handleScroll1() {
            const scrollView = this.$refs.scrollView;
            if (
                scrollView.scrollHeight -
                scrollView.scrollTop -
                scrollView.clientHeight <=
                10
            ) {
                this.isBottoma = true;
            } else {
                this.isBottoma = false;
            }
        },
        confirm() {
            this.alertshow = false;
            this.alertshow1 = false;
        },
        async serviceAgreement() {
            this.alertshow = true;
            const res = await this.$service.post({
                url: "/api/zp/v1/zp_agreement",
                data: {
                    type: "1",
                },
            });
            if (res.code == 1) {
                this.zp_agreement = res.info;
            }
            if (res.code != -1 && res.code != 1) {
                this.$message(res.msg);
            }
        },
        async privacyAgreement() {
            this.alertshow1 = true;
            this.alertshow = false;
            const res = await this.$service.post({
                url: "/api/zp/v1/zp_agreement",
                data: {
                    type: "2",
                },
            });
            if (res.code == 1) {
                this.zp_agreement = res.info;
            }
            if (res.code != -1 && res.code != 1) {
                this.$message(res.msg);
            }
        },
        checkPrivacy() {
            this.checkFlag = !this.checkFlag;
        },
        async sendcode() {
            if (this.isSending) {
                return;
            }
            //获取验证码
            const res = await this.$service.post({
                url: smsUrl,
                data: {
                    mobile: this.mobile,
                    // mobile_code: this.mobile_code,
                    scene: this.scene,
                },
            });
            // this.$message(res.msg);
            if (res.code == 1) {
                this.$message.success(res.msg);
                this.startCountdown();
            }
            if (res.code != -1 && res.code != 1) {
                this.$message(res.msg);
            }
        },
        async sendcodea() {
            if (this.isSending) {
                return;
            }
			this.loading = this.$loading({
				lock: true,
				text: '获取中',
				spinner: 'el-icon-loading',
				background: 'rgba(255, 255, 255, 0.7)'
			})
            //获取验证码
            const res = await this.$service.post({
                url: smsUrl,
                data: {
                    mobile: this.mobilesecond,
                    scene: this.scene,
                },
            });
			if (this.loading) {
				this.loading.close()
			}
            if (res.code == 1) {
                this.$message.success(res.msg);
                this.startCountdown();
            }
            if (res.code != -1 && res.code != 1) {
                this.$message(res.msg);
            }
        },
        startCountdown() {
            this.isSending = true;
            this.countdown = 60;
            const btn = this.$refs.sendBtn;
            this.timer = setInterval(() => {
                if (this.countdown <= 0) {
                    this.stopCountdown();
                } else {
                    this.countdown--;
                }
            }, 1000)
        },
        stopCountdown() {
            this.isSending = false;
            this.countdown = 0;
            clearInterval(this.timer);
            this.timer = null;
        },
        // 校验手机号
        validateMobile(mobile) {
            const regex = /^1[3-9]\d{9}$/;
            return regex.test(mobile);
        },
        validateMobileBlur() {
            if (!this.validateMobile(this.mobile)) {
                this.$message('请输入有效的手机号');
                return;
            }
        },
        validateMobileSecond(mobilesecond) {
            const regex = /^1[3-9]\d{9}$/;
            return regex.test(mobilesecond);
        },
        validateMobileBlurSecond() {
            if (!this.validateMobileSecond(this.mobilesecond)) {
                this.$message('请输入有效的手机号');
                return;
            }
        },
        async login() {

            // console.log('2t43246322');
            // 校验手机号
            if (!this.validateMobile(this.mobile)) {
                this.$message("请输入有效的手机号");
                return;
            }
            //账号密码登录
            if (!this.checkFlag) {
                this.$message("请阅读并同意服务及隐私协议");
                return;
            }
			
            if (this.codetextshow == false && this.codeshow == true) {
				this.isLoading = true
                const res1 = await this.$service.post({
                    url: "/api/zp/v1/zp_code_login", //验证码登录
                    data: {
                        mobile: this.mobile,
                        mobile_code: this.mobile_code,
                        is_comp: 1,
                    },
                });
				if (this.loading) {
					this.loading.close()
				}
                if (res1.code == 1) {
                    
                    localStorage.setItem('token', res1.info.token);
                    localStorage.setItem("username", res1.info.user_name);
                    localStorage.setItem("is_comp", res1.info.is_comp);
                    localStorage.setItem("avatar user_logo", res1.info.avatar);
                    localStorage.setItem("user_id", res1.info.user_id);
                    this.$router.push("/index");
                    setTimeout(() => {
                        this.isLoading = false
                    }, 1000);
                } else {
                    this.$message(res1.msg);
                    return;
                }
            } else {
				this.isLoading = true
                const res = await this.$service.post({
					
                    url: "/api/zp/v1/zp_login",
                    data: {
                        mobile: this.mobile,
                        password: this.password,
                        is_comp: 1,
                    },
                });
				if (this.loading) {
					this.loading = false
				}
                // console.log(res);
                if (res.code == 1) {
                    localStorage.setItem('token', res.info.token);
                    localStorage.setItem("username", res.info.username);
                    localStorage.setItem("is_comp", res.info.is_comp);
                    localStorage.setItem("avatar user_logo", res.info.avatar);
                    localStorage.setItem("user_id", res.info.user_id);
                    this.$router.push("/index");
                }
                if (res.code != -1 && res.code != 1) {
                    this.$message(res.msg);
                }
            }
        },
        codelogin() {
            this.codetextshow = false;
            this.codeshow = true;
            this.pswshow = false;
        },
        pswlogin() {
            this.codetextshow = true;
            this.codeshow = false;
            this.pswshow = true;
        },
        codeloginaa() {
            this.codetextshowa = false;
            this.codeshowa = true;
            this.pswshowa = false;
        },
        pswloginaa() {
            this.codetextshowa = true;
            this.codeshowa = false;
            this.pswshowa = true;
        },
        async loginsecond() {
            // 校验手机号
            if (!this.validateMobileSecond(this.mobilesecond)) {
                this.$message("请输入有效的手机号");
                return;
            }
            if (!this.checkFlag) {
                this.$message("请阅读并同意服务及隐私协议");
                return;
            }
            if (this.codetextshowa == false && this.codeshowa == true) {

                const res1 = await this.$service.post({
                    url: "/api/zp/v1/zp_code_login", //验证码登录
                    data: {
                        mobile: this.mobilesecond,
                        mobile_code: this.mobile_code,
                        is_comp: 2,
                        // scene: this.scene,
                    },
                });
                if (res1.code == 1) {
                    this.isLoading = true
                    localStorage.setItem('token', res1.info.token);
                    localStorage.setItem("username", res1.info.user_name);
                    localStorage.setItem("is_comp", res1.info.is_comp);
                    localStorage.setItem("avatar user_logo", res1.info.avatar);

                    localStorage.setItem("is_perfect", res.info.is_perfect);
                    setTimeout(() => {
                        this.isLoading = false
                    }, 1000);
                    if (res1.info.is_perfect == 0) {
                        this.$message('登陆成功，请先完善企业信息！');
                        setTimeout(() => {
                            this.$router.push("./eInformation")
                        }, 2000);
                        return
                    }
					console.log(456)
                    this.$router.push("/enterprisePosition");
                }
                if (res1.code != -1 && res1.code != 1) {
                    this.$message(res1.msg);
                }

            } else {
                const res = await this.$service.post({
                    url: "/api/zp/v1/zp_login",
                    data: {
                        mobile: this.mobilesecond,
                        password: this.passwordsecond,
                        is_comp: 2,
                    },
                });
                this.isLoading = false
                if (res.code == 1) {
                    localStorage.setItem('token', res.info.token);
                    localStorage.setItem("username", res.info.username);
                    localStorage.setItem("is_comp", res.info.is_comp);
                    localStorage.setItem("avatar user_logo", res.info.avatar);
                    localStorage.setItem("company_id", res.info.user_id);
                    localStorage.setItem("is_perfect", res.info.is_perfect);
                    if (res.info.is_perfect == 0) {
                        this.$message('登陆成功，请先完善企业信息！');
                        setTimeout(() => {
                            this.$router.push("./eInformation")
                        }, 2000);
                        return
                    }
					console.log(123)
                    this.$router.push("/enterprisePosition");
                }
                if (res.code != -1 && res.code != 1) {
                    this.$message(res.msg);
                }
            }
        },
        pregister() {
            this.$router.push("/pInformation");
        },
        index() {
            this.$router.push("/index");
        },
        register() {
            this.$router.push("/cInformation");
        },
        handleClick(tab, event) {
        },
        //忘记密码
        forgetLogin(vue) {
            this.$router.push(`/forgotPassword?is_comp=${vue}`)
        }
    },
    components: {
        elLogo,
        elFooterss,
    },
};
</script>

<style scoped>
* {
    background-color: #fff;
}

body * {
    cursor: default;
}

button.send {
    /* width: 85px; */
    height: 25px;
    background-color: #FCE9E8;
    border: none;
    color: #FF0000;
    line-height: 25px;
    padding: 0 5px;
    box-sizing: border-box;
    position: absolute;
    top: 8px;
    left: 200px;
}

.send.disabled {
    cursor: not-allowed;
    opacity: 0.6;
    background: #f3f3f3;
}

.el-header {
    background-color: #fff;
    height: 100px;
    padding: 0;
}

.checkBtnInfo {
    width: 281px;
    font-family: PingFangSC, PingFang SC;
    font-weight: 400;
    font-size: 13px;
    color: #999999;
    line-height: 20px;
    text-align: left;
    font-style: normal;
    margin-left: 16px;
    position: relative;
}

.checkBtnInfo span {
    color: #496cb3;
}

.codelogin {
    font-size: 14px;
    margin-bottom: 10px;
    text-align: right;
    text-decoration: underline;
    color: #dd0000;
}

.forget_login {
    font-size: 14px;
    margin-bottom: 10px;
    text-align: right;
    color: #dd0000;
    margin-top: -19px;
}

input.inputcheck {
    position: absolute;
    top: 106px;
    left: 0;
}

input.inputcheck1 {
    position: absolute;
    top: 1px;
    left: -19px;
}

.tit {
    background-color: #fff;
    width: 1200px;
    height: 100px;
    margin: 0 auto;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    position: relative;
}

.left {
    height: 60px;
    width: 210px;
    display: flex;
    align-items: center;
    background-color: #fff;
}

.left div {
    background-color: #fff;
}

.tit img.logo {
    width: 221px;
    height: 55px;
    /* width: 55px; */
}

.text div:nth-child(2) {
    font-size: 7px;
}

.text i {
    font-weight: 600;
    background-color: #fff;
}

.right {
    width: 170px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
}

.right img {
    width: 20px;
    height: 20px;
    background-color: #fff;
}

.right span {
    background-color: #fff;
}

.box {
    width: 100%;
    height: 100%;
}

.box img {
    width: 100%;
    height: 673px;
}

.con {
    width: 1200px;
    height: 100%;
    margin: 0 auto;
    margin-top: -626px;
    background-color: transparent;
}

.cc,
.zx {
    position: relative;
    color: #fff;
    font-size: 38px;
    background-color: unset !important;
    width: 230px;
    font-family: SFNSDisplay;
    text-shadow: 0px 2px 4px rgba(0, 0, 0, 0.5);
}

.cc {
    top: 200px;
    left: 200px;
}

.zx {
    top: 210px;
    left: 238px;
}

.job {
    width: 310px;
    position: relative;
    color: #fff;
    background: unset !important;
    top: 250px;
    left: 200px;
    font-size: 18px;
    font-family: PingFangSC, PingFang SC;
}

.info {
    position: relative;
    width: 350px;
    height: 400px;
    background-color: #fff;
    border-radius: 10px;
    left: 660px;
    padding: 10px 30px;
    box-sizing: border-box;
}

::v-deep .el-tabs__content {
    top: 30px;
}

::v-deep .el-tabs__nav-scroll {
    background: #fff;
    display: flex;
    justify-content: space-around;
}

::v-deep .el-tabs__item.is-active {
    color: #d90403;
    font-weight: 600;
}

::v-deep .el-tabs__item {
    background: #fff;
    font-size: 18px;
    color: #666666;
}

::v-deep .el-tabs__nav-wrap::after {
    display: none;
}

::v-deep .el-tabs__active-bar {
    display: none;
}

::v-deep .el-input__inner {
    width: 290px;
    height: 40px;
}

/* ::v-deep .el-input .el-input__clear {
    background: #fff;
}

::v-deep .el-input__prefix,
.el-input__suffix {
    position: absolute;
    top: 7px;
    text-align: center;
}

::v-deep .el-input__suffix-inner {
    pointer-events: all;
    background: #fff;
}
::v-deep .el-input__suffix {
    right: 5px;
    transition: all 0.3s;
    pointer-events: none;
    background: #fff;
} */

.linebb {
    width: 288px;
    border: 1px solid #dcdcdc;
    position: absolute;
    top: 55px;
}


.title {
    background: #fff;
    height: 50px;
    border-bottom: 1px solid #f3f3f3;
    font-size: 18px;
    line-height: 50px;
    display: flex;
    justify-content: space-around;
    margin-bottom: 40px;
}

.title span {
    background: #fff;
}

.title span:hover {
    color: #dd0000;
}

.el-input {
    margin-bottom: 10px;
    background: #fff;
}

.el-radio {
    background: #fff;
}

::v-deep .el-radio__label,
::v-deep .el-radio__input {
    background: #fff;
    font-size: 13px;
}

.el-radio__input {
    white-space: nowrap;
    cursor: pointer;
    outline: 0;
    line-height: 1;
    vertical-align: middle;
    background: #fff;
}

.el-radio__inner.el-radio__inner {
    background: #fff;
    border-radius: 25%;
}

button.login {
    width: 100%;
    height: 40px;
    background-color: #dd0000 !important;
    color: #fff;
    margin-top: 25px;
    border: none;
    border-radius: 4px;
}

.code {
    position: relative;
}



.come {
    font-size: 14px;
    margin-top: 20px;
    background: #fff;
}

.come span {
    color: #dd0000;
    background: #fff;
    margin-left: 5px;
}

.alert {
    background-color: rgba(0, 0, 0, 0.45) !important;
    bottom: 0;
    height: 100%;
    left: 0;
    position: fixed;
    right: 0;
    top: 0;
    z-index: 1000;
    display: flex;
    justify-content: center;
}

.alert .title {
    height: 55px;
    word-wrap: break-word;
    color: rgba(0, 0, 0, 0.85);
    font-size: 18px;
    font-weight: 500;
    margin: 0;
    display: block;
    padding: 0 24px;
    box-sizing: border-box;
    line-height: 55px;
    border: none;
}

.alert .alertbox {
    width: 520px;
    /* height: 850px; */
    height: 90%;
    margin: 50px 0;
    background-color: #fff;
    border-radius: 2px;
    display: flex;  
    flex-direction: column;
    align-items: center;
    justify-content: center; 
    padding-bottom: 20px;
    box-sizing: border-box;
}

.alert .alertbox .content {
    width: 500px;
    /* height: 700px;0 */
    height: 74%;
    background-color: #fff;
    overflow: auto;
    padding: 24px 0 24px 24px;
    box-sizing: border-box;
    overflow-x: hidden;
}

::v-deep .alert .alertbox .content * {
    background-color: #fff;
}

.alert .alertbox .line1 {
    width: 520px;
    height: 1px;
    background-color: #f3f3f3;
    margin-bottom: 20px;
}

.alert .alertbox .line2 {
    width: 520px;
    height: 1px;
    background-color: #f3f3f3;
    margin-top: 20px;
}


button.confirm {
    width: 66px;
    height: 30px;
    /* background: #f5f5f5;
    border-color: #d9d9d9; */
    background: #d00;
    /* position: relative;
    left: 0; */
    font-size: 16px;
    border: none;
    color: #fff;
    /* position: relative;
    top: 11px;
    left: 440px; */
    margin-top: 20px;
    margin-left: 85%;
}

::v-deep .alertbox .el-button {
    width: 66px;
    height: 30px;
    padding: 0;
    background: #f5f5f5;
    border-color: #d9d9d9;
    line-height: 30px;
    /* position: relative;
    top: 11px;
    left: 440px; */
}

::v-deep .boxx_33,
::v-deep .boxx_34,
::v-deep .textt_43,
::v-deep .textt_44,
::v-deep .textt_46,
::v-deep .textt_47,
::v-deep .textt_49,
::v-deep .textt_50 {
    display: none !important;
}

::v-deep .groupp_44 {
    margin-top: 20px;
}


.alert .alertbox {
    width: 520px;
    /* height: 850px; */
    height: 80%;
    margin: 50px 0;
    background-color: #fff;
    border-radius: 2px;
}

/* .alert .alertbox .content {
    width: 500px;
    height: 700px;0
    height: 82%;
    background-color: #fff;
    overflow: auto;
    padding: 24px 0 24px 24px;
    box-sizing: border-box;
    overflow-x: hidden;
} */
.is-red {
    background-color: red !important;
    /* 使用 !important 确保覆盖 Element UI 的默认样式 */
    color: white;
    /* 文字颜色，根据需要设置 */
}
</style>
